<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> 


    <script type="text/javascript" src="http://api.map.baidu.com/api?ak=PlhFWpA02aoURjAOpnWcRGqw7AI8EEyO&v=2.0&services=false"></script> 
</head>
<script src="./jquery.min.js"></script>
<input type="text" id="name">
<input type="text" id="pwd">
<button id="btn">登录</button>

<div id="allmap"></div>
<body>
    <script>
        function jsonpStr(url, arg, cb) {
            // 1拼接字符串  参数  如  id=1&name="小名"
            var queryString = "";
            for (var key in arg) {
                queryString += key + "=" + arg[key] + "&"
            }
            url += "?" + queryString;
            // 加上callback
            // 响应回来的有点（.）所以从第二位开始  截取
            var cbName = 'jsonp_' + Math.random().toString().substr(2);
            console.log(cbName)
            //window.jsonp_2182192=callback;
            window[cbName] = function (data) {
                cb(data);
                document.body.removeChild(scriptElement);
            };
            url = url + 'cb=' + cbName;
            // 2创建script标签  并且把拼接后的URL放到src上
            var scriptElement = document.createElement('script');
            scriptElement.src = url;
            // 3.把script标签加入到页面里
            document.body.appendChild(scriptElement);
        }

        jsonpStr("https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su", { wd: 'angular' },
            function (data) {
                console.log(data)

            })

        function jsonp({ url, params, cb }) {
            return new Promise((resolve, reject) => {
                let script = document.createElement("script");
                window[cb] = function (data) {
                    resolve(data);
                    document.body.removeChild(script);
                }
                params = { ...params, cb };//wd=b&cb=show
                let arrs = [];
                for (let key in params) {
                    arrs.push(`${key}=${params[key]}`)
                }
                script.src = `${url}?${arrs.join('&')}`;
                document.body.appendChild(script);

            })
        }

        jsonp({
            url: "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su",
            params: { wd: 'angular' },
            cb: "show"
        }).then(data => {
            console.log(data)
        })
        
$("#btn").click(function(){
    $.ajax({
            type: 'post',
            url: 'http://localhost:8000/login',
            data:JSON.stringify(
                {
                name:$("#name").val(),
                pwd:$("#pwd").val()
            }
            ),
            headers: { 
                        'Content-Type': 'application/json;charset=utf-8'  //multipart/form-data;boundary=--xxxxxxx   application/json
                    },  
            dataType:"json",
            success: function (data) {
                if(data==500){
                    alert("登录失败")
                }else{
                    alert("登录成功")
                }
                console.log(data);
            },
            error: function () {
                console.log('error');
            }
        })
})
   



    </script>
<script type="text/javascript">  
    document.write('IP地址:' + returnCitySN["cip"] + ', CID:' + returnCitySN["cid"] + ', 地区:' + returnCitySN["cname"]+",浏览器版本:"+getBrowserInfo());
    
    function getBrowserInfo()
{
var agent = navigator.userAgent.toLowerCase() ;

var regStr_ie = /msie [\d.]+;/gi ;
var regStr_ff = /firefox\/[\d.]+/gi
var regStr_chrome = /chrome\/[\d.]+/gi ;
var regStr_saf = /safari\/[\d.]+/gi ;

//IE
if(agent.indexOf("msie") > 0)
{
    return agent.match(regStr_ie) ;
}

//firefox
if(agent.indexOf("firefox") > 0)
{
    return agent.match(regStr_ff) ;
}

//Chrome
if(agent.indexOf("chrome") > 0)
{
    return agent.match(regStr_chrome) ;
}

//Safari
if(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0)
{
    return agent.match(regStr_saf) ;
}

}



</script>
</body>

</html>